package com.xnsy.jishexiangmu.controller;

import com.xnsy.jishexiangmu.pojo.LunTan;
import com.xnsy.jishexiangmu.pojo.PingLun;
import com.xnsy.jishexiangmu.service.luntan.LunTanServer;
import com.xnsy.jishexiangmu.uitl.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/luntan")

public class LunTanController {
    @Autowired
    private LunTanServer lunTanServer;
    @GetMapping("/get")
    public Result get(){
        List<LunTan> lunTans = lunTanServer.get();
        return Result.success(lunTans);
    }
    @GetMapping("/adddianzan")
    public Result addDianZan (@RequestParam Integer id){
        lunTanServer.addDianZan(id);
        return Result.success("点赞成功");
    }
    @PostMapping("add")
    public Result addMessage(@RequestBody LunTan lunTan){
        lunTanServer.addMessage(lunTan);
        return Result.success("发布成功");
    }
    @GetMapping("/getone")
    public Result getOne(@RequestParam Integer id){
        LunTan lunTan = lunTanServer.getOne(id);
        return Result.success(lunTan);
    }
    @GetMapping("/getpinglun")
    public Result getPingLun(Integer pid){
        List<PingLun> pingLuns = lunTanServer.getPingLun(pid);
       return Result.success(pingLuns);
    }
    @RequestMapping("/addpinglun")
    public  Result addPingLun (@RequestBody PingLun pingLun){
        lunTanServer.addPingLun(pingLun);
        return Result.success("评论成功");
    }

}
